import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:tv_friso_screen/utils/phone_info_utils.dart';
import 'package:tv_friso_screen/utils/result_check_utils.dart';
import 'package:tv_friso_screen/widget/map.dart';
import 'package:tv_friso_screen/widget/marquee_widget.dart';
import 'package:tv_friso_screen/widget/option_gridview.dart';

import 'data_model/home_info.dart';
import 'data_model/k_value.dart';
import 'model/response_with_object.dart';
import 'net/api_address.dart';
import 'net/data_helper.dart';
import 'net/http_manager.dart';
import 'package:intl/date_symbol_data_local.dart'; // 添加此行
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'dart:ui';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var scrollController = ScrollController();

  // 组件ListView的实例对象
  ScrollController autoScontroller = ScrollController();
  Timer? timer;
  Timer? timerPeriodic;
  Timer? mTimer; //页面定时刷新计时器
  Timer? downTimer; //右上角时分秒显示倒计时
  // 设置滚动的距离
  double offset = 0;

  HomeInfo? mHomeData;

  //全部数据 7个
  List<KValue> allItems = [];
  List<String> zoneIndex = ["东区", "西区", "南区", "北区"];
  List<String> topIcons = [
    "assets/images/icon_one.png",
    "assets/images/icon_two.png",
    "assets/images/icon_three.png",
    "assets/images/icon_four.png",
    "assets/images/icon_five.png",
  ];

  var selectPIndex = -1; //点击选中的省份城市 集合下标

  var nowTime = "";

  //全区销售数据统计（第二版单页面app接口）
  void getHomeData() async {
    var params = {};
    var formData = DataHelper.getBaseMapParams(params);
    var response =
        await HttpManager().get(ApiAddress.getMainData, query: formData);

    if (response['data'] != null &&
        response['code'] == HttpManager.codeSuccess) {
      ResponseWithObject<HomeInfo> data =
          ResponseWithObject.fromJson(response as Map<String, dynamic>, (j) {
        if (j != null) {
          return HomeInfo.fromJson(j);
        } else {
          return j;
        }
      });
      if (data.code == HttpManager.codeSuccess && mounted) {
        //给首页赋值
        setState(() {
          mHomeData = data.data;

          allItems.clear();

          //首页头部今日数据
          if (null != mHomeData!.totalData) {
            allItems
                .add(KValue("今日皇家美素(箱)", mHomeData!.totalData.prestigeGoods));
            allItems.add(
                KValue("今日源悦(箱)", mHomeData!.totalData.dLGoods.toString()));
            allItems.add(KValue("今日旺玥(箱)", mHomeData!.totalData.immuGoods));
            allItems.add(KValue("今日米粉(箱)", mHomeData!.totalData.goldGoods));
            allItems.add(KValue("今日活跃门店", mHomeData!.totalData.shopNumber));
            allItems
                .add(KValue("皇家活跃", mHomeData!.totalData.prestigeShopNumber));
            allItems.add(KValue("源悦活跃", mHomeData!.totalData.dLShopNumber));
          }
        });
      } else {
        if (mounted) {
          ResultCheckUtils.checkResult(context, data.code, data.msg);
        }
      }
    }
  }

  void startTimer() {
    mTimer = Timer.periodic(const Duration(seconds: 15 * 60), (timer) {
      //每隔 15 分钟 刷新一次数据
      getHomeData();
    });
  }

  void countDownTimer() {
    downTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
      //每隔 1 秒钟 刷新一次时分秒
      setState(() {
        nowTime = PhoneInfoUtils.getTime();
      });
    });
  }

  @override
  void initState() {
    super.initState();

    final width2 = window.physicalSize.width;
    final height2 = window.physicalSize.height;
    print("屏幕的宽高1-------- $width2 $height2");
    print(
        "屏幕的宽高2-------- ${ScreenUtil().screenWidth} ${ScreenUtil().screenHeight}");

    getHomeData();

    timerPeriodic = Timer.periodic(const Duration(milliseconds: 100), (timer) {
      if (null != mHomeData && mHomeData!.saleDetail.isNotEmpty) {
        offset++;
        // autoScontroller.jumpTo(offset);
        autoScontroller.animateTo(offset,
            duration: const Duration(milliseconds: 100), curve: Curves.linear);
      }
    });

    // 滚动监听事件
    autoScontroller.addListener(() {
      if (null != mHomeData && mHomeData!.saleDetail.isNotEmpty) {
        if (autoScontroller.position.pixels <= 0) {
        } else if (autoScontroller.position.pixels >=
            autoScontroller.position.maxScrollExtent) {
          setState(() {
            offset = 0;
          });
        }
      }
    });

    //定时器 15分钟 刷新一次首页数据
    startTimer();

    countDownTimer();
  }

  @override
  void dispose() {
    super.dispose();
    timer?.cancel();
    timerPeriodic?.cancel();
    autoScontroller.dispose();

    mTimer?.cancel();
    downTimer?.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: const BoxDecoration(
          image: DecorationImage(
            image: AssetImage(
              "assets/images/icon_bg_back.png",
            ),
            fit: BoxFit.fill,
          ),
        ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              flex: 3,
              child: Column(
                children: [
                  /*今日数据信息*/
                  Container(
                    margin: EdgeInsets.only(
                      left: 88.w,
                      top: 120.w,
                    ),
                    child: allItems.isEmpty
                        ? Container()
                        : OptionGridView(
                            itemCount: allItems.length,
                            rowCount: 4,
                            mainAxisSpacing: 10,
                            crossAxisSpacing: 10,
                            itemBuilder: (BuildContext context, int index) {
                              return Container(
                                alignment: Alignment.center,
                                padding: EdgeInsets.all(10.w),
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.all(
                                    Radius.circular(5.w),
                                  ),
                                  border: Border.all(
                                    color: const Color(0xFF829EEE),
                                    width: 1.w,
                                  ),
                                ),
                                child: Column(
                                  children: [
                                    Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.center,
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: [
                                        Text(
                                          allItems[index].name,
                                          maxLines: 1,
                                          overflow: TextOverflow.ellipsis,
                                          style: TextStyle(
                                            color: const Color(0xFF1ED2FF),
                                            fontSize: 16.sp,
                                            fontWeight: FontWeight.bold,
                                          ),
                                        ),
                                        Visibility(
                                          visible: allItems[index]
                                                  .name
                                                  .contains("皇家活跃") ||
                                              allItems[index]
                                                  .name
                                                  .contains("源悦活跃"),
                                          child: Text(
                                            "(MTD/P3M)",
                                            maxLines: 1,
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                              color: const Color(0xFF1ED2FF),
                                              fontSize: 14.sp,
                                              fontWeight: FontWeight.bold,
                                            ),
                                          ),
                                        ),
                                      ],
                                      //(MTD/P3M)
                                    ),
                                    SizedBox(
                                      height: 10.w,
                                    ),
                                    Text(
                                      allItems[index].value,
                                      style: TextStyle(
                                        color: const Color(0xFFFFCA9A),
                                        fontSize: 16.sp,
                                        fontWeight: FontWeight.bold,
                                      ),
                                    ),
                                    SizedBox(
                                      height: 5.w,
                                    ),
                                  ],
                                ),
                              );
                            },
                            scrollController: scrollController,
                          ),
                  ),
                  underline(30.w, 88.w, 0, 30.w),
                  /*中国地图*/
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: EdgeInsets.only(
                      top: 15.w,
                      left: 88.w,
                    ),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          "销售覆盖区域",
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 26.sp,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        Container(
                          alignment: Alignment.center,
                          width: double.infinity,
                          child: Stack(
                            children: [
                              Container(
                                width: double.infinity,
                                alignment: Alignment.centerRight,
                                margin:
                                    EdgeInsets.only(top: 150.w, right: 25.w),
                                child: Text(
                                  selectPIndex == -1
                                      ? ""
                                      : "${mHomeData!.salesRegion[selectPIndex].pname}: ${mHomeData!.salesRegion[selectPIndex].nums}",
                                  style: TextStyle(
                                    color: const Color(0xFF1ED2FF),
                                    fontSize: 18.sp,
                                    fontWeight: FontWeight.bold,
                                  ),
                                  textAlign: TextAlign.end,
                                ),
                              ),
                              Container(
                                width: double.infinity,
                                alignment: Alignment.center,
                                child: MapWidget(
                                  callBack: (String name) {
                                    if (null != mHomeData &&
                                        mHomeData!.salesRegion.isNotEmpty) {
                                      for (var i = 0;
                                          i < mHomeData!.salesRegion.length;
                                          i++) {
                                        if (mHomeData!.salesRegion[i].pname
                                            .contains(name)) {
                                          setState(() {
                                            selectPIndex = i;
                                          });
                                          break;
                                        }
                                      }
                                    }
                                  },
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                    child: Container(
                      alignment: Alignment.centerLeft,
                      margin: EdgeInsets.only(
                        top: 15.w,
                        left: 88.w,
                        bottom: 80.w,
                      ),
                      padding: EdgeInsets.only(
                        top: 20.w,
                        left: 35.w,
                        bottom: 10.w,
                      ),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.all(
                          Radius.circular(10.w),
                        ),
                        border: Border.all(
                          color: const Color(0xFF829EEE),
                          width: 1.w,
                        ),
                      ),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            "实时销售明细",
                            style: TextStyle(
                              color: const Color(0xFF1ED2FF),
                              fontSize: 22.sp,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                          SizedBox(
                            height: 15.w,
                          ),
                          Expanded(
                            child: null == mHomeData ||
                                    mHomeData!.saleDetail.isEmpty
                                ? Container()
                                : ListView.builder(
                                    shrinkWrap: true,
                                    itemCount: mHomeData!.saleDetail.length,
                                    scrollDirection: Axis.vertical,
                                    controller: autoScontroller,
                                    itemBuilder:
                                        (BuildContext context, int index) {
                                      var data = mHomeData!.saleDetail[index];
                                      return Container(
                                        margin: EdgeInsets.only(
                                            bottom: 15.w, right: 35.w),
                                        child: Row(
                                          children: [
                                            Text(
                                              data.date,
                                              style: TextStyle(
                                                color: const Color(0xFF1ED2FF),
                                                fontSize: 18.sp,
                                                fontWeight: FontWeight.bold,
                                              ),
                                            ),
                                            SizedBox(
                                              width: 15.w,
                                            ),
                                            Text(
                                              data.time,
                                              style: TextStyle(
                                                color: const Color(0xFF1ED2FF),
                                                fontSize: 18.sp,
                                                fontWeight: FontWeight.bold,
                                              ),
                                            ),
                                            SizedBox(
                                              width: 15.w,
                                            ),
                                            Text(
                                              data.shopName,
                                              style: TextStyle(
                                                color: const Color(0xFF1ED2FF),
                                                fontSize: 18.sp,
                                                fontWeight: FontWeight.bold,
                                              ),
                                            ),
                                            Expanded(
                                              child: Text(
                                                data.regionAddress,
                                                textAlign: TextAlign.end,
                                                style: TextStyle(
                                                  color:
                                                      const Color(0xFF1ED2FF),
                                                  fontSize: 18.sp,
                                                  fontWeight: FontWeight.bold,
                                                ),
                                              ),
                                            ),
                                          ],
                                        ),
                                      );
                                    },
                                  ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Expanded(
              flex: 4,
              child: Column(
                children: [
                  Container(
                    width: double.infinity,
                    margin: EdgeInsets.only(top: 20.w, right: 45.w),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                        Text(
                          nowTime,
                          style: TextStyle(
                            color: const Color(0xFFFFFFFF),
                            fontSize: 24.sp,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        SizedBox(
                          width: 20.w,
                        ),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              getWeekDay(),
                              style: TextStyle(
                                color: const Color(0xFFFFFFFF),
                                fontSize: 24.sp,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                            Text(
                              PhoneInfoUtils.getDate(),
                              style: TextStyle(
                                color: const Color(0xFFFFFFFF),
                                fontSize: 24.sp,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  Container(
                    width: double.infinity,
                    margin: EdgeInsets.only(left: 20.w, top: 35.w, right: 49.w),
                    padding: EdgeInsets.only(
                      bottom: 15.w,
                    ),
                    // color: const Color(0xFF829EEE),
                    color: const Color(0x260085F7),
                    child: mHomeData == null
                        ? Container()
                        : Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              //东西南北
                              underline(0.w, 0.w, 5.w, 30.w),
                              zoneWidget(mHomeData!.zoneEast, 0),
                              underline(20.w, 0.w, 5.w, 30.w),
                              zoneWidget(mHomeData!.zoneWest, 1),
                              underline(20.w, 0.w, 5.w, 30.w),
                              zoneWidget(mHomeData!.zoneSouth, 2),
                              underline(20.w, 0.w, 5.w, 30.w),
                              zoneWidget(mHomeData!.zoneNorth, 3),
                            ],
                          ),
                  ),
                  Expanded(
                    child: Container(
                      margin:
                          EdgeInsets.only(bottom: 80.w, top: 20.w, right: 49.w),
                      padding: EdgeInsets.only(left: 72.w, right: 40.w),
                      child: Row(
                        children: [
                          Expanded(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                underline(0.w, 0.w, 10.w, 10.w),
                                Row(
                                  children: [
                                    Image.asset(
                                      "assets/images/icon_trangle.png",
                                      width: 14.w,
                                      height: 29.w,
                                    ),
                                    SizedBox(
                                      width: 15.w,
                                    ),
                                    Text(
                                      "本月Top5销售(省份)",
                                      style: TextStyle(
                                        color: const Color(0xFFFFFFFF),
                                        fontSize: 24.sp,
                                        fontWeight: FontWeight.bold,
                                      ),
                                    ),
                                  ],
                                ),
                                underline(15.w, 0.w, 0, 10.w),
                                Expanded(
                                  child: Container(
                                    margin: EdgeInsets.only(top: 20.w),
                                    padding: EdgeInsets.only(
                                        left: 20.w,
                                        top: 16.w,
                                        right: 20.w,
                                        bottom: 15.w),
                                    decoration: BoxDecoration(
                                      borderRadius: BorderRadius.all(
                                        Radius.circular(10.w),
                                      ),
                                      border: Border.all(
                                        color: const Color(0xFF829EEE),
                                        width: 1.w,
                                      ),
                                    ),
                                    child: mHomeData == null ||
                                            mHomeData!.saleProvince.isEmpty
                                        ? Container()
                                        : ListView.builder(
                                            shrinkWrap: true,
                                            itemCount:
                                                mHomeData!.saleProvince.length,
                                            scrollDirection: Axis.vertical,
                                            itemBuilder: (BuildContext context,
                                                int index) {
                                              return Container(
                                                margin: EdgeInsets.only(
                                                    bottom: 15.w, right: 35.w),
                                                child: Row(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment.center,
                                                  mainAxisAlignment:
                                                      MainAxisAlignment.center,
                                                  children: [
                                                    Image.asset(
                                                      topIcons[index],
                                                      width: 18.w,
                                                      height: 24.w,
                                                    ),
                                                    SizedBox(
                                                      width: 15.w,
                                                    ),
                                                    Expanded(
                                                      child: Text(
                                                        // "浙江省宁波市余姚市",
                                                        mHomeData!
                                                            .saleProvince[index]
                                                            .regionProvince,
                                                        textAlign:
                                                            TextAlign.left,
                                                        style: TextStyle(
                                                          color: const Color(
                                                              0xFF1ED2FF),
                                                          fontSize: 18.sp,
                                                          fontWeight:
                                                              FontWeight.bold,
                                                        ),
                                                      ),
                                                    ),
                                                  ],
                                                ),
                                              );
                                            },
                                          ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          SizedBox(
                            width: 45.w,
                          ),
                          Expanded(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                underline(0.w, 0.w, 10.w, 10.w),
                                Row(
                                  children: [
                                    Image.asset(
                                      "assets/images/icon_trangle.png",
                                      width: 14.w,
                                      height: 29.w,
                                    ),
                                    SizedBox(
                                      width: 15.w,
                                    ),
                                    Text(
                                      "本月Top5销售(城市)",
                                      style: TextStyle(
                                        color: const Color(0xFFFFFFFF),
                                        fontSize: 24.sp,
                                        fontWeight: FontWeight.bold,
                                      ),
                                    ),
                                  ],
                                ),
                                underline(15.w, 0.w, 0, 10.w),
                                Expanded(
                                  child: Container(
                                    width: double.infinity,
                                    margin: EdgeInsets.only(top: 20.w),
                                    padding: EdgeInsets.only(
                                        left: 20.w,
                                        top: 16.w,
                                        right: 20.w,
                                        bottom: 15.w),
                                    decoration: BoxDecoration(
                                      borderRadius: BorderRadius.all(
                                        Radius.circular(10.w),
                                      ),
                                      border: Border.all(
                                        color: const Color(0xFF829EEE),
                                        width: 1.w,
                                      ),
                                    ),
                                    child: mHomeData == null ||
                                            mHomeData!.saleCity.isEmpty
                                        ? Container()
                                        : ListView.builder(
                                            shrinkWrap: true,
                                            itemCount:
                                                mHomeData!.saleCity.length,
                                            scrollDirection: Axis.vertical,
                                            itemBuilder: (BuildContext context,
                                                int index) {
                                              return Container(
                                                margin: EdgeInsets.only(
                                                    bottom: 15.w, right: 35.w),
                                                child: Row(
                                                  children: [
                                                    Image.asset(
                                                      // "assets/images/icon_one.png",
                                                      topIcons[index],
                                                      width: 18.w,
                                                      height: 24.w,
                                                    ),
                                                    SizedBox(
                                                      width: 15.w,
                                                    ),
                                                    Expanded(
                                                      child: Text(
                                                        // "浙江省宁波市余姚市",
                                                        mHomeData!
                                                            .saleCity[index]
                                                            .regionProvince,
                                                        textAlign:
                                                            TextAlign.left,
                                                        style: TextStyle(
                                                          color: const Color(
                                                              0xFF1ED2FF),
                                                          fontSize: 18.sp,
                                                          fontWeight:
                                                              FontWeight.bold,
                                                        ),
                                                      ),
                                                    ),
                                                  ],
                                                ),
                                              );
                                            },
                                          ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  //走马灯效果
  MarqueeWidget buildMarqueeWidget(List<String> loopList) {
    ///上下轮播 安全提示
    return MarqueeWidget(
      //子Item构建器
      itemBuilder: (BuildContext context, int index) {
        String itemStr = loopList[index];
        //通常可以是一个 Text文本
        return Container(
          height: 45.h,
          padding: EdgeInsets.only(
            left: 15.w,
          ),
          alignment: Alignment.centerLeft,
          child: Text(
            itemStr,
            style: TextStyle(
              color: Colors.white,
              fontSize: 26.sp,
            ),
            softWrap: true,
            overflow: TextOverflow.ellipsis,
          ),
        );
      },
      //循环的提示消息数量
      count: loopList.length,
    );
  }

  Widget underline(double top, double left, double bottom, double mWidth) {
    return Container(
      margin: EdgeInsets.only(
        top: top,
        left: left,
        bottom: bottom,
      ),
      color: const Color(0xFF0F5FAF),
      width: double.infinity,
      height: 1.5.w,
      child: Stack(
        children: [
          Container(
            color: const Color(0xff00B7FE),
            width: mWidth,
            height: 2.w,
          ),
        ],
      ),
    );
  }

  Widget emptyWidget(double top, double left, double mWidth) {
    return Container(
      margin: EdgeInsets.only(
        top: top,
        left: left,
      ),
      color: const Color(0xff1ED2FF),
      width: 25.w,
      height: 2.w,
    );
  }

  //东西南北区
  Widget zoneWidget(Zone data, int index) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            SizedBox(
              width: 11.w,
            ),
            Image.asset(
              "assets/images/icon_trangle.png",
              width: 14.w,
              height: 29.w,
            ),
            SizedBox(
              width: 10.w,
            ),
            Text(
              zoneIndex[index],
              style: TextStyle(
                color: const Color(0xFFFFFFFF),
                fontSize: 24.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
        SizedBox(
          height: 15.w,
        ),
        Row(
          children: [
            SizedBox(
              width: 10.w,
            ),
            Expanded(
              child: zoneItem("今日皇家(箱)", data.prestigeGoods),
            ),
            SizedBox(
              width: 10.w,
            ),
            Expanded(
              child: zoneItem("今日源悦(箱)", data.dLGoods),
            ),
            SizedBox(
              width: 10.w,
            ),
            Expanded(
              child: zoneItem("今日米粉(箱)", data.goldGoods),
            ),
            SizedBox(
              width: 10.w,
            ),
            Expanded(
              child: zoneItem("今日旺玥(箱)", data.immuGoods),
            ),
            SizedBox(
              width: 10.w,
            ),
            Expanded(
              child: zoneItem("今日活跃门店", data.shopNumber),
            ),
            SizedBox(
              width: 10.w,
            ),
            Expanded(
              child: zoneItem("皇家活跃", data.prestigeShopNumber),
            ),
            SizedBox(
              width: 10.w,
            ),
            Expanded(
              child: zoneItem("源悦活跃", data.dLShopNumber),
            ),
            SizedBox(
              width: 10.w,
            ),
            Expanded(
              child: zoneItem("米粉活跃", data.goldShopNumber),
            ),
            SizedBox(
              width: 10.w,
            ),
          ],
        ),
      ],
    );
  }

  Widget zoneItem(String title, String value) {
    return Container(
      alignment: Alignment.center,
      padding: EdgeInsets.all(10.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.all(
          Radius.circular(5.w),
        ),
        border: Border.all(
          color: const Color(0xFF829EEE),
          width: 1.w,
        ),
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                title,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                  color: const Color(0xFF1ED2FF),
                  fontSize: 11.sp,
                  fontWeight: FontWeight.bold,
                ),
              ),
              Visibility(
                visible: title.contains("皇家活跃") ||
                    title.contains("源悦活跃") ||
                    title.contains("米粉活跃"),
                child: Container(
                  margin: EdgeInsets.only(top: 3.w),
                  child: Text(
                    "(MTD/P3M)",
                    style: TextStyle(
                      color: const Color(0xFF1ED2FF),
                      fontSize: 9.sp,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
              ),
            ],
          ),
          SizedBox(
            height: 5.w,
          ),
          value.isEmpty
              ? emptyWidget(0, 0, 0)
              : Text(
                  value,
                  style: TextStyle(
                    color: const Color(0xFFFFCA9A),
                    fontSize: 16.sp,
                    fontWeight: FontWeight.bold,
                  ),
                ),
        ],
      ),
    );
  }

  //获取周几
  String getWeekDay() {
    DateTime now = DateTime.now(); // 获取当前日期和时间

    String weekDay;
    switch (now.weekday) {
      case DateTime.monday:
        weekDay = "星期一";
        break;
      case DateTime.tuesday:
        weekDay = "星期二";
        break;
      case DateTime.wednesday:
        weekDay = "星期三";
        break;
      case DateTime.thursday:
        weekDay = "星期四";
        break;
      case DateTime.friday:
        weekDay = "星期五";
        break;
      case DateTime.saturday:
        weekDay = "星期六";
        break;
      default:
        weekDay = "星期天";
        break;
    }
    return weekDay;
  }
}
